<?php


namespace App\Http\Controllers\Api\v1;


use App\Http\Controllers\Api\BaseController;
use App\Http\Controllers\Controller;
use App\servers\CurlServer;
use App\servers\FaceServer;
use Illuminate\Http\Request;

class RecognitionController extends BaseController
{
    /**
     * 人脸检测
     */
    public function actionRun() {
        $face =new FaceServer();
        $image = 'https://img2.baidu.com/it/u=3354585195,1512541150&fm=253&fmt=auto&app=138&f=JPEG?w=890&h=500';
        $data = $face->facedete($image,'URL');
        return $data;
    }
    /**
     *  添加用户组
     */
    public function actionAddGroup(Request $request){
        try {
            $group = $request->post('group_name');
            $face =new FaceServer();
            $res = $face->addGrooup($group);
            return $this->witejson(0,$res,'添加成功');
        }catch (\Exception $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }
    }
    /**
     *  删除用户组
     */
    public function actionDelGroup(Request $request){
        try {
            $group = $request->post('group_name');
            $face =new FaceServer();
            $res = $face->delGroup($group);
            return $this->witejson('0',$res,'删除成功');
        }catch (\Exception $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }
    }
    /**
     * 添加人脸
     * @param Request $request
     * @return array|false|string
     */
    public function actionUserAdd(Request $request)
    {
        try {
            dd($request->file());
            $QniuImg='https://2008a-zfw.oss-cn-shanghai.aliyuncs.com/rules.jpg';
            $face =new FaceServer();
            $res = $face->userAdd($QniuImg,'URL','wjy2008a2','1');
            return $this->witejson(0,$res,'人脸添加成功');
        }catch (\Exception $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }
    }
    /**
     * 人脸搜索
     */
    public function actionSeachFace(Request $request)
    {
        try {
//            $image = 'https://2008a-zfw.oss-cn-shanghai.aliyuncs.com/rules.jpg';
            $image = 'http://rubycmk1i.bkt.clouddn.com/031F220B6B82CEC94CDE8BC2893AB440.png';
//            $image = 'https://ts2.cn.mm.bing.net/th?id=OIP-C.ekfq34aN4t_4oQ9rNlecRgHaLH&w=204&h=306&c=8&rs=1&qlt=90&o=6&dpr=1.1&pid=3.1&rm=2';
            $face = new FaceServer();
            $res = $face->fachSeach($image,'URL','wjy2008a2','1');
            return $this->witejson(0,$res,'人脸识别成功');
        } catch (\Exception $exception){
            return $this->witejson(1,'',$exception->getMessage());
        }

    }
}
